home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap01 / howto03 / delphi10 / win16tb.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-06-11  |  29.9 KB  |  916 lines

  1. unit Win16tb;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Menus, ShellAPI;
  8.  
  9. type
  10.   TCCTaskBarForm = class(TForm)
  11.     Panel1: TPanel;
  12.     BitBtn1: TBitBtn;
  13.     BitBtn2: TBitBtn;
  14.     BitBtn3: TBitBtn;
  15.     BitBtn4: TBitBtn;
  16.     BitBtn5: TBitBtn;
  17.     BitBtn6: TBitBtn;
  18.     BitBtn7: TBitBtn;
  19.     OpenDialog1: TOpenDialog;
  20.     PopupMenu1: TPopupMenu;
  21.     StartAsIcon1: TMenuItem;
  22.     AddFile1: TMenuItem;
  23.     ShowOnBottom1: TMenuItem;
  24.     ShowOnTop1: TMenuItem;
  25.     PopupMenu2: TPopupMenu;
  26.     NewFile1: TMenuItem;
  27.     MoveUp1: TMenuItem;
  28.     MoveDown1: TMenuItem;
  29.     Delete1: TMenuItem;
  30.     procedure BitBtn2Click(Sender: TObject);
  31.     procedure FormCreate(Sender: TObject);
  32.     procedure BitBtn1Click(Sender: TObject);
  33.     procedure FormDestroy(Sender: TObject);
  34.     procedure BitBtn5Click(Sender: TObject);
  35.     procedure BitBtn6Click(Sender: TObject);
  36.     procedure BitBtn7Click(Sender: TObject);
  37.     procedure BitBtn3Click(Sender: TObject);
  38.     procedure BitBtn4Click(Sender: TObject);
  39.     procedure StartAsIcon1Click(Sender: TObject);
  40.     procedure ShowOnBottom1Click(Sender: TObject);
  41.     procedure ShowOnTop1Click(Sender: TObject);
  42.     procedure AddFile1Click(Sender: TObject);
  43.     procedure NewFile1Click(Sender: TObject);
  44.     procedure Delete1Click(Sender: TObject);
  45.     procedure MoveUp1Click(Sender: TObject);
  46.     procedure MoveDown1Click(Sender: TObject);
  47.     procedure BitBtn5MouseDown(Sender: TObject; Button: TMouseButton;
  48.       Shift: TShiftState; X, Y: Integer);
  49.     procedure BitBtn6MouseDown(Sender: TObject; Button: TMouseButton;
  50.       Shift: TShiftState; X, Y: Integer);
  51.     procedure BitBtn7MouseDown(Sender: TObject; Button: TMouseButton;
  52.       Shift: TShiftState; X, Y: Integer);
  53.     procedure BitBtn5MouseUp(Sender: TObject; Button: TMouseButton;
  54.       Shift: TShiftState; X, Y: Integer);
  55.     procedure BitBtn6MouseUp(Sender: TObject; Button: TMouseButton;
  56.       Shift: TShiftState; X, Y: Integer);
  57.     procedure BitBtn7MouseUp(Sender: TObject; Button: TMouseButton;
  58.       Shift: TShiftState; X, Y: Integer);
  59.   private
  60.     { Private declarations }
  61.   public
  62.     { Public declarations }
  63.     procedure ReadTheTaskBarIniFile;     { This reads in the program data     }
  64.     procedure WriteTheTaskBarIniFile;    { This writes out the program data   }
  65.     procedure SetUpTheTaskBar;           { This sets up the icon/data array   }
  66.     procedure DeleteTasksFrom( TheTask : Integer ); { Fiddle w record array   }
  67.     procedure ReplaceFile( CurrentSelection : Integer ); { Replace file       }
  68.   end;                         { and puts the first 3 into view     }
  69.   PTBRecord = ^TBRecord;                      { Define pointer type }
  70.   TBRecord = record                          { Define record type  }
  71.     TheName : String;                         { Holds program name  }
  72.     TheBitmap : TBitmap;                      { Holds bitmpd icon   }
  73.     TheIcon   : TIcon;
  74.   end;
  75.   PTBArray = array[ 1 .. 255 ] of PTBRecord;  { Working data array  }
  76.  
  77. var
  78.   CCTaskBarForm: TCCTaskBarForm;
  79.   ThePTBArray        : PTBArray; { This holds the data array from INI }
  80.   TotalTaskEntries   : Integer;  { This is the total items to use     }
  81.   CurrentTaskPointer : Integer;  { This is the position to start disp }
  82.   DeleteMode         : Boolean;  { This is a flag indicating deletion }
  83.   ShowPosition       : Integer;  { This handles staring at top/bottom }
  84.   StartingState      : Integer;  { This handles normal/icon startup   }
  85.   TotalTaskPointers  : Integer;  { This keeps track of the total tasks}
  86.   CurrentTaksPointer : Integer;  { This holds current task to run     }
  87.   ActiveButton       : TBitBtn;  { This holds the identity of the btn }
  88.   SaveStartupDir     : String;   { This holds the starting directory  }
  89. implementation
  90.  
  91. {$R *.DFM}
  92.  
  93. uses
  94.   IniFiles ;  { Ini file handler unit       }
  95.  
  96. const
  97.  
  98.   TaskBarIniFileName = 'CCTSKBAR.INI';  { Make this a constant to save stack space }
  99.  
  100.  
  101. function ShellExec(const PathStr, CmdStr, DirStr: string;
  102.   PrintIt: boolean; Show: word; Wait: boolean): boolean;
  103. var
  104.   Inst: THandle;
  105.   Path, CmdLine, Dir: PChar;
  106.   Op: array[0..5] of Char;
  107.   AppWin: hWnd;
  108.   Valid: Bool;
  109. begin
  110.   if PrintIt then StrPCopy(Op, 'print') else StrPCopy(Op, 'open');
  111.   { Get memory for PChars }
  112.   GetMem(Path, Length(PathStr)+1);
  113.   GetMem(CmdLine, Length(CmdStr)+1);
  114.   GetMem(Dir, Length(DirStr)+1);
  115.   try
  116.     { Copy strings to PChars }
  117.     StrPCopy(Path, PathStr);
  118.     StrPCopy(CmdLine, CmdStr);
  119.     StrPCopy(Dir, DirStr);
  120.     { Execute file }
  121.     Inst := ShellExecute(0, Op, Path, CmdLine, Dir, Show);
  122.     { If 32 or less, an error occurred }
  123.     if Inst <= 32 then Result := False else
  124.     begin
  125.       if Wait then
  126.       begin
  127.         { Loop while program is running }
  128.         while GetModuleUsage(Inst) <> 0 do
  129.           Application.ProcessMessages;
  130.         { Acknowledge error from last iteration of loop }
  131.         OutputDebugString('--> Please ignore the previous error'#10#13);
  132.       end;
  133.       Result := True;
  134.     end;
  135.   finally
  136.     { Ensure memory is freed }
  137.     FreeMem(Path, Length(PathStr)+1);
  138.     FreeMem(CmdLine, Length(CmdStr)+1);
  139.     FreeMem(Dir, Length(DirStr)+1);
  140.   end;
  141. end;
  142.  
  143. procedure TCCTaskBarForm.ReplaceFile( CurrentSelection : Integer );
  144. var ThePChar   : PChar;
  145.     TheOtherPChar ,
  146.     TheResultPChar : PChar;
  147.     TheExt ,
  148.     TempString : String;
  149. begin
  150.   GetMem( ThePChar , 255 );
  151.   if OpenDialog1.Execute then
  152.   begin
  153.     with ThePTBArray[ CurrentSelection ]^ do
  154.     begin
  155.       TheName := OpenDialog1.Filename;
  156.       TheExt := Uppercase( ExtractFileExt( TheName ));
  157.       if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  158.           ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  159.       begin
  160.         GetMem( TheOtherPChar , 255 );
  161.         GetMem( TheResultPChar , 255 );
  162.         StrPCopy( ThePChar, TheName );
  163.         StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  164.         if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  165.         begin
  166.           TheIcon.Free;
  167.           TheIcon := TIcon.Create;
  168.           TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  169.         end
  170.         else
  171.         begin
  172.           MessageDlg( 'No Application Registered for this File Type!',mtError,[mbok],0);
  173.           TheIcon.Handle := 0;
  174.         end;
  175.         FreeMem( TheOtherPChar , 255 );
  176.         FreeMem( TheResultPChar , 255 );
  177.       end
  178.       else
  179.       begin
  180.         StrPCopy( ThePChar , TheName );
  181.         TheIcon.Free;
  182.         TheIcon := TIcon.Create;
  183.         TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  184.       end;
  185.       if TheIcon.Handle <> 0 then
  186.       begin
  187.         TheBitmap.Canvas.Draw( 1,1,TheIcon );
  188.       end
  189.       else
  190.       begin
  191.         TheBitmap.LoadFromFile( SaveStartupDir +'\Default.bmp' );
  192.       end;
  193.     end;
  194.     SetupTheTaskBar;
  195.   end;
  196.   FreeMem( ThePChar , 255 );
  197. end;
  198.  
  199. procedure TCCTaskBarForm.DeleteTasksFrom( TheTask : Integer );
  200. var Counter_1 : Integer;
  201. begin
  202.   if TheTask = TotalTaskEntries then
  203.   begin
  204.     ThePTBArray[ TheTask ]^.TheName := '';
  205.     ThePTBArray[ TheTask ]^.TheBitmap.LoadFromFile( SaveStartupDir + '\NOFILE.BMP' );
  206.     TotalTaskEntries := TotalTaskEntries - 1;
  207.   end
  208.   else
  209.   begin
  210.     for Counter_1 := TheTask + 1 to TotalTaskEntries do
  211.     begin
  212.       with ThePTBArray[ Counter_1 ]^ do
  213.       begin
  214.         ThePTBArray[ Counter_1 - 1 ]^.TheName := TheName;
  215.         ThePTBArray[ Counter_1 - 1 ]^.TheBitmap.Canvas.Draw( 0 , 0 , TheIcon );
  216.       end;
  217.     end;
  218.     if TotalTaskEntries > 3 then
  219.     begin
  220.       ThePTBArray[ TotalTaskEntries ]^.TheBitmap.Free;
  221.       ThePTBArray[ TotalTaskEntries ]^.TheIcon.Free;
  222.       Dispose( ThePTBArray[ TotalTaskEntries ] );
  223.       TotalTaskEntries := TotalTaskEntries - 1;
  224.     end
  225.     else
  226.     begin
  227.       ThePTBArray[ TotalTaskEntries ]^.TheName := '';
  228.       ThePTBArray[ TotalTaskEntries ]^.TheBitmap.LoadFromFile( SaveStartupDir + '\NOFILE.BMP' );
  229.       TotalTaskEntries := TotalTaskEntries - 1;
  230.     end;
  231.   end;
  232. end;
  233.  
  234. procedure TCCTaskBarForm.SetupTheTaskBar;
  235. var Counter_1      : Integer;
  236.     WorkingPointer : Integer;
  237. begin
  238.   if TotalTaskEntries < 3 then
  239.   begin
  240.     case TotalTaskEntries of
  241.       0 : begin
  242.             BitBtn5.Caption := 'No File';
  243.             BitBtn5.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  244.             BitBtn6.Caption := 'No File';
  245.             BitBtn6.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  246.             BitBtn7.Caption := 'No File';
  247.             BitBtn7.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  248.           end;
  249.       1 : begin
  250.             BitBtn6.Caption := 'No File';
  251.             BitBtn6.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  252.             BitBtn7.Caption := 'No File';
  253.             BitBtn7.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  254.           end;
  255.       2 : begin
  256.             BitBtn7.Caption := 'No File';
  257.             BitBtn7.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  258.           end;
  259.     end;
  260.   end;
  261.   WorkingPointer := CurrentTaskPointer - 1;
  262.   for Counter_1 := 1 to 3 do
  263.   begin
  264.     WorkingPointer := WorkingPointer + 1;
  265.     if WorkingPointer > TotalTaskEntries then break;
  266.     with ThePTBArray[ WorkingPointer ]^ do
  267.     begin
  268.       case Counter_1 of
  269.         1 : begin
  270.               BitBtn5.Caption := ExtractFileName( TheName );
  271.               BitBtn5.Glyph := TheBitmap;
  272.             end;
  273.         2 : begin
  274.               BitBtn6.Caption := ExtractFileName( TheName );
  275.               BitBtn6.Glyph := TheBitmap;
  276.             end;
  277.         3 : begin
  278.               BitBtn7.Caption := ExtractFileName( TheName );
  279.               BitBtn7.Glyph := TheBitmap;
  280.             end;
  281.       end;
  282.     end;
  283.   end;
  284.   if TotalTaskEntries > 3 then BitBtn4.Enabled := true
  285.    else BitBtn4.Enabled := false;
  286.   if CurrentTaskPointer > 1 then BitBtn3.Enabled := true
  287.    else BitBtn3.Enabled := false;
  288. end;
  289.  
  290. { This procedure reads in the configuration from an INI file }
  291. procedure TCCTaskBarForm.ReadTheTaskBarIniFile;
  292. var
  293.    { The excellent TIniFile object handles the complexity of Windows INI files! }
  294.    TheIniFile : TIniFile;
  295.    TempString,
  296.    TempString2 : String;
  297.    Counter_1  : Integer;
  298.    ThePChar   : PChar;
  299.    TheFileCounterString : String;
  300.  
  301. begin
  302.   GetMem( ThePchar , 255 );
  303.   CurrentTaskPointer := 1;
  304.   { Combine assignfile and reset into one call with create }
  305.   TheIniFile := TIniFile.Create( TaskBarIniFileName );
  306.   { Use a try block to make sure the ini file is closed by free call }
  307.   try
  308.     { Use the Tinifile object's read methods to get the configuration data }
  309.     with TheIniFile do
  310.     begin
  311.       { Use readinteger to get the total taskbar entries, with default of 0 for new file }
  312.       TotalTaskEntries := ReadInteger( 'Setup', 'TotalEntries', 0 );
  313.       { Use readinteger to get the total taskbar entries, with default of 0 for new file }
  314.       ShowPosition := ReadInteger( 'Setup', 'StartPosition', 0 );
  315.       { Use readinteger to get the total taskbar entries, with default of 0 for new file }
  316.       StartingState := ReadInteger( 'Setup', 'StartState', 1 );
  317.       if TotalTaskEntries = 0 then
  318.       begin
  319.         GetWindowsDirectory( ThePChar , 255 );
  320.         TempString2 := StrPas( ThePChar );
  321.         TempString := TempString2;
  322.         if FileExists( TempString + '\PBRUSH.EXE' ) then
  323.         begin
  324.           New( ThePTBArray[ 1 ] );
  325.           with ThePTBArray[ 1 ]^ do
  326.           begin
  327.             TempString := TempString + '\PBRUSH.EXE';
  328.             TheName := TempString;
  329.             TheBitmap := TBitmap.Create;
  330.             TheBitmap.Height := 32;
  331.             TheBitmap.Width := 32;
  332.             StrPCopy( ThePChar , TempString );
  333.             TheIcon := TIcon.Create;
  334.             TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  335.             if TheIcon.Handle <> 0 then
  336.             begin
  337.               TheBitmap.Canvas.Draw( 1,1,TheIcon );
  338.             end
  339.             else
  340.             begin
  341.               TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  342.             end;
  343.           end;
  344.           TotalTaskEntries := 1;
  345.         end;
  346.         TempString := TempString2;
  347.         if FileExists( TempString + '\WRITE.EXE' ) then
  348.         begin
  349.           New( ThePTBArray[ 2 ] );
  350.           with ThePTBArray[ 2 ]^ do
  351.           begin
  352.             TempString := TempString + '\WRITE.EXE';
  353.             TheName := TempString;
  354.             TheBitmap := TBitmap.Create;
  355.             TheBitmap.Height := 32;
  356.             TheBitmap.Width := 32;
  357.             StrPCopy( ThePChar , TempString );
  358.             TheIcon := TIcon.Create;
  359.             TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  360.             if TheIcon.Handle <> 0 then
  361.             begin
  362.               TheBitmap.Canvas.Draw( 1,1,TheIcon );
  363.             end
  364.             else
  365.             begin
  366.               TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  367.             end;
  368.             TotalTaskEntries := TotalTaskEntries + 1;
  369.           end;
  370.         end;
  371.         TempString := TempString2;
  372.         if FileExists( TempString + '\CONTROL.EXE' ) then
  373.         begin
  374.           New( ThePTBArray[ 3 ] );
  375.           with ThePTBArray[ 3 ]^ do
  376.           begin
  377.             TempString := TempString + '\CONTROL.EXE';
  378.             TheName := TempString;
  379.             TheBitmap := TBitmap.Create;
  380.             TheBitmap.Height := 32;
  381.             TheBitmap.Width := 32;
  382.             StrPCopy( ThePChar , TempString );
  383.             TheIcon := TIcon.Create;
  384.             TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  385.             if TheIcon.Handle <> 0 then
  386.             begin
  387.               TheBitmap.Canvas.Draw( 1,1,TheIcon );
  388.             end
  389.             else
  390.             begin
  391.               TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  392.             end;
  393.           end;
  394.           TotalTaskEntries := TotalTaskEntries + 1;
  395.         end;
  396.       end
  397.       else
  398.       begin
  399.         for Counter_1 := 1 to TotalTaskEntries do
  400.         begin
  401.           TheFileCounterString := 'FileNo_' + IntToStr( Counter_1 );
  402.           TempString := ReadString( 'FileList', TheFileCounterString, '' );
  403.           New( ThePTBArray[ Counter_1 ] );
  404.           with ThePTBArray[ Counter_1 ]^ do
  405.           begin
  406.             TheName := TempString;
  407.             TheBitmap := TBitmap.Create;
  408.             TheBitmap.Height := 32;
  409.             TheBitmap.Width := 32;
  410.             StrPCopy( ThePChar , TempString );
  411.             TheIcon := TIcon.Create;
  412.             TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  413.             if TheIcon.Handle <> 0 then
  414.             begin
  415.               TheBitmap.Canvas.Draw( 1,1,TheIcon );
  416.             end
  417.             else
  418.             begin
  419.               TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  420.             end;
  421.           end;
  422.         end;
  423.       end;
  424.     end;
  425.   finally
  426.     { Regardless of success or failure, free the TIniFile object }
  427.     TheIniFile.Free;
  428.     FreeMem( ThePChar , 255 );
  429.   end;
  430. end;
  431.  
  432. { This procedure writes out the configuration to an INI file }
  433. procedure TCCTaskBarForm.WriteTheTaskBarIniFile;
  434. var
  435.    { Again use the very useful TIniFile object to encapsulate Windows INI files }
  436.    TheIniFile : TIniFile;
  437.    TempString : String;
  438.    Counter_1 : Integer;
  439. begin
  440.   { Combine an AssignFile and Reset call into the create method }
  441.   TheIniFile := TIniFile.Create( TaskBarIniFileName );
  442.   try
  443.     { Use the TIniFile object's methods to write out the data }
  444.     with TheIniFile do
  445.     begin
  446.       { Use writeinteger to send the total entries in the program }
  447.       WriteInteger( 'Setup' , 'TotalEntries' , TotalTaskEntries );
  448.       { Use writeinteger to send the total entries in the program }
  449.       WriteInteger( 'Setup' , 'StartPosition' , ShowPosition );
  450.       { Use writeinteger to send the total entries in the program }
  451.       WriteInteger( 'Setup' , 'StartState' , StartingState );
  452.       for Counter_1 := 1 to TotalTaskEntries do
  453.       begin
  454.         TempString := 'FileNo_' + IntToStr( Counter_1 );
  455.         { Use writestring to send the Working directory for image files }
  456.         WriteString( 'FileList' , TempString , ThePTBArray[ Counter_1 ]^.TheName );
  457.       end;
  458.     end;
  459.   finally
  460.     { Regardless of above calls, free the TIniFile object }
  461.     TheIniFile.Free;
  462.   end;
  463. end;
  464.  
  465.  
  466. { This was written by Delphi; use it to simply close the form since }
  467. { the INI file is updated continually                               }
  468. procedure TCCTaskBarForm.BitBtn2Click(Sender: TObject);
  469. begin
  470.   { Go bye bye }
  471.   close;
  472. end;
  473.  
  474. { This was written by Delphi; use it to size the form on the bottom and }
  475. { place the buttons according to screen size. Then read in the INI file }
  476. { and set up the data lists and set the first three buttons (or less.)  }
  477. procedure TCCTaskBarForm.FormCreate(Sender: TObject);
  478. var WorkingSpace    ,              { This is the basic area to work with  }
  479.     WorkingDivision ,              { If more than enough use this for lng }
  480.     WorkingLength     : Integer;   { If less than enough use this for len }
  481. begin
  482.   {GlobalUpdate := CCFMUpdate;}
  483.   GetDir( 0 , SaveStartupDir );
  484.   { Set to the screen's width }
  485.   Width := Screen.Width - 2;
  486.   { Move to the left edge }
  487.   Left := 1;
  488.   { Set the exit button's position }
  489.   BitBtn2.Left := Screen.Width - 145;
  490.   { Set the right scroll button's position }
  491.   BitBtn4.Left := BitBtn2.Left - 45;
  492.   { Determine how much room is left }
  493.   WorkingSpace := BitBtn4.left - 200;
  494.   { if plenty of room spread out }
  495.   if WorkingSpace >= 575 then
  496.   begin
  497.     { Divide into 3 chunks }
  498.     WorkingDivision := WorkingSpace div 3;
  499.     { Start at the left edge }
  500.     BitBtn5.Left := 200;
  501.     { Move across one }
  502.     BitBtn6.Left := 210 + WorkingDivision;
  503.     { Move across two }
  504.     BitBtn7.Left := 220 + WorkingDivision * 2;
  505.   end
  506.   else
  507.   begin { Narrow the buttons down to fit the available space }
  508.     { Divide into 3 chunks }
  509.     WorkingLength := ( WorkingSpace div 3 );
  510.     { Set the button widths to less than the chunks }
  511.     BitBtn5.Width := WorkingLength - 15;
  512.     BitBtn6.Width := WorkingLength - 15;
  513.     BitBtn7.Width := WorkingLength - 15;
  514.     { Start at the left edge }
  515.     BitBtn5.left := 200;
  516.     { Move across one }
  517.     BitBtn6.Left := 210 + WorkingLength;
  518.     { Move across two }
  519.     BitBtn7.Left := 220 + ( WorkingLength * 2 );
  520.   end;
  521.   { Read in the INI file data and initialize }
  522.   ReadTheTaskBarIniFile;
  523.   { Move to the bottom of the screen }
  524.   if ShowPosition = 0 then Top := Screen.Height - 90 else Top := 1;
  525.   if StartingState = 0 then
  526.   begin
  527.     WindowState := wsMinimized;
  528.     StartAsIcon1.Checked := true;
  529.   end
  530.   else
  531.   begin
  532.     windowstate := wsnormal;
  533.     StartAsIcon1.Checked := false;
  534.   end;
  535.   SetUpTheTaskBar;
  536.   CurrentTaskPointer := 1;
  537. end;
  538.  
  539. { Delphi wrote this; use it to minimize the form so icons can be seen }
  540. { (since have put in an (invisible) system box, double clicking the   }
  541. { icon will bring back up to max state.)                              }
  542. procedure TCCTaskBarForm.BitBtn1Click(Sender: TObject);
  543. begin
  544.   { Turn into an icon for user friendliness }
  545.   WindowState := wsMinimized;
  546. end;
  547.  
  548. { Delphi wrote this; use it to clean up the memory used by the records array }
  549. procedure TCCTaskBarForm.FormDestroy(Sender: TObject);
  550. var Counter_1 : Integer;
  551. begin
  552.   for Counter_1 := 1 to TotalTaskEntries do
  553.   begin
  554.     ThePTBarray[ Counter_1 ]^.TheBitmap.Free;
  555.     ThePTBArray[ Counter_1 ]^.TheIcon.Free;
  556.     Dispose( ThePTBArray[ Counter_1 ] );
  557.   end;
  558. end;
  559.  
  560. procedure TCCTaskBarForm.BitBtn5Click(Sender: TObject);
  561. var
  562.   TheActiveWindow    : HWnd;
  563.   TheFileNametoShell : String;
  564.   TheWindowList      : Pointer;
  565. begin
  566.   if TotalTaskEntries = 0 then exit;
  567.   TheFileNametoShell := ThePTBArray[ CurrentTaskPointer ]^.Thename;
  568.   if TheFileNametoShell = '' then exit;
  569.   TheWindowList := DisableTaskWindows( 0 );
  570.   TheActiveWindow := GetActiveWindow;
  571.   try
  572.     if not ShellExec( TheFileNametoShell , '' , '', false ,
  573.       SW_SHOWNORMAL , false ) then
  574.     MessageDlg('Could not Execute Task!', mtInformation, [mbOK], 0);
  575.   finally
  576.     EnableTaskWindows( TheWindowList );
  577.     SetActiveWindow( TheActiveWindow );
  578.   end;
  579. end;
  580.  
  581. procedure TCCTaskBarForm.BitBtn6Click(Sender: TObject);
  582. var
  583.   TheActiveWindow    : HWnd;
  584.   TheFileNametoShell : String;
  585.   TheWindowList      : Pointer;
  586. begin
  587.   if CurrentTaskPointer + 1 > TotalTaskEntries then Exit;
  588.   TheFileNametoShell := ThePTBArray[ CurrentTaskPointer + 1 ]^.Thename;
  589.   TheWindowList := DisableTaskWindows( 0 );
  590.   TheActiveWindow := GetActiveWindow;
  591.   try
  592.     if not ShellExec( TheFileNametoShell , '' , '', false ,
  593.       SW_SHOWNORMAL , false ) then
  594.     MessageDlg('Could not Execute Task!', mtInformation, [mbOK], 0);
  595.   finally
  596.     EnableTaskWindows( TheWindowList );
  597.     SetActiveWindow( TheActiveWindow );
  598.   end;
  599. end;
  600.  
  601. procedure TCCTaskBarForm.BitBtn7Click(Sender: TObject);
  602. var
  603.   TheActiveWindow    : HWnd;
  604.   TheFileNametoShell : String;
  605.   TheWindowList      : Pointer;
  606. begin
  607.   if CurrentTaskPointer + 2 > TotalTaskEntries then exit;
  608.   TheFileNametoShell := ThePTBArray[ CurrentTaskPointer + 2 ]^.Thename;
  609.   TheWindowList := DisableTaskWindows( 0 );
  610.   TheActiveWindow := GetActiveWindow;
  611.   try
  612.     if not ShellExec( TheFileNametoShell , '' , '', false ,
  613.       SW_SHOWNORMAL , false ) then
  614.     MessageDlg('Could not Execute Task!', mtInformation, [mbOK], 0);
  615.   finally
  616.     EnableTaskWindows( TheWindowList );
  617.     SetActiveWindow( TheActiveWindow );
  618.   end;
  619. end;
  620.  
  621. { Delphi wrote this; use it to move the button list one place left }
  622. procedure TCCTaskBarForm.BitBtn3Click(Sender: TObject);
  623. begin
  624.   if CurrentTaskPointer = 1 then exit else
  625.   begin
  626.     CurrentTaskPointer := CurrentTaskPointer - 1;
  627.     SetUpTheTaskBar;
  628.     if CurrentTaskPointer = 1 then BitBtn3.Enabled := false;
  629.     if CurrentTaskPointer < ( TotalTaskEntries - 2 ) then
  630.      BitBtn4.Enabled := true;
  631.   end;
  632. end;
  633.  
  634. { Delphi wrote this; use it to move the button list one place right }
  635. procedure TCCTaskBarForm.BitBtn4Click(Sender: TObject);
  636. begin
  637.   if CurrentTaskPointer >= ( TotalTaskEntries - 2 ) then exit else
  638.   begin
  639.     CurrentTaskPointer := CurrentTaskPointer + 1;
  640.     SetUpTheTaskBar;
  641.     if CurrentTaskPointer = ( TotalTaskEntries - 2 ) then
  642.      BitBtn4.Enabled := false;
  643.     if CurrentTaskPointer > 1 then BitBtn3.Enabled := true;
  644.   end;
  645. end;
  646.  
  647. procedure TCCTaskBarForm.StartAsIcon1Click(Sender: TObject);
  648. begin
  649.   if StartingState = 0 then
  650.   begin
  651.     StartingState := 1;
  652.     StartAsIcon1.Checked := false;
  653.   end
  654.   else
  655.   begin
  656.     StartingState := 0;
  657.     StartAsIcon1.checked := true;
  658.   end;
  659.   WriteTheTaskBarIniFile;
  660. end;
  661.  
  662. procedure TCCTaskBarForm.ShowOnBottom1Click(Sender: TObject);
  663. begin
  664.   ShowPosition := 0;
  665.   ShowOnBottom1.Checked := true;
  666.   ShowOnTop1.Checked := false;
  667.   WriteTheTaskBarIniFile;
  668.   if Top = 1 then
  669.   begin
  670.     Top := Screen.Height - 90;
  671.   end;
  672. end;
  673.  
  674. procedure TCCTaskBarForm.ShowOnTop1Click(Sender: TObject);
  675. begin
  676.   ShowPosition := 1;
  677.   ShowOnBottom1.Checked := false;
  678.   ShowOnTop1.Checked := true;
  679.   WriteTheTaskBarIniFile;
  680.   if Top <> 1 then
  681.   begin
  682.     Top := 1;
  683.   end;
  684. end;
  685.  
  686. procedure TCCTaskBarForm.AddFile1Click(Sender: TObject);
  687. var ThePChar   ,
  688.     TheOtherPChar,
  689.     TheResultPChar : PChar;
  690.     TheExt ,
  691.     TempString : String;
  692. begin
  693.   if TotalTaskEntries = 255 then
  694.   begin
  695.     MessageDlg( 'Maximum Taskbar Entries Reached!',mtError,[mbOk],0);
  696.     exit;
  697.   end;
  698.   GetMem( ThePChar , 255 );
  699.   if OpenDialog1.Execute then
  700.   begin
  701.     TotalTaskEntries := TotalTaskEntries + 1;
  702.     New( ThePTBArray[ TotalTaskEntries ] );
  703.     with ThePTBArray[ TotalTaskEntries ]^ do
  704.     begin
  705.       TheName := OpenDialog1.Filename;
  706.       TheBitmap := TBitmap.Create;
  707.       TheIcon := TIcon.Create;
  708.       TheBitmap.Height := 32;
  709.       TheBitmap.Width := 32;
  710.       TheExt := Uppercase( ExtractFileExt( TheName ));
  711.       if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  712.           ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  713.       begin
  714.         GetMem( TheOtherPChar , 255 );
  715.         GetMem( TheResultPChar , 255 );
  716.         StrPCopy( ThePChar, TheName );
  717.         StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  718.         if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  719.         begin
  720.           TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  721.         end
  722.         else
  723.         begin
  724.           MessageDlg( 'No Application Registered for this File Type!',mtError,[mbok],0);
  725.           TheIcon.Handle := 0;
  726.         end;
  727.         FreeMem( TheOtherPChar , 255 );
  728.         FreeMem( TheResultPChar , 255 );
  729.       end
  730.       else
  731.       begin
  732.         StrPCopy( ThePChar , TheName );
  733.         TheIcon := TIcon.Create;
  734.         TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  735.       end;
  736.       if TheIcon.Handle <> 0 then
  737.       begin
  738.         TheBitmap.Canvas.Draw( 1,1,TheIcon );
  739.       end
  740.       else
  741.       begin
  742.         TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  743.       end;
  744.     end;
  745.     SetupTheTaskBar;
  746.   end;
  747.   FreeMem( ThePChar , 255 );
  748.   if TotalTaskEntries = 255 then AddFile1.Enabled := false;
  749. end;
  750.  
  751. procedure TCCTaskBarForm.NewFile1Click(Sender: TObject);
  752. begin
  753.   if ActiveButton = BitBtn5 then
  754.   begin
  755.     if TotalTaskEntries = 0 then exit;
  756.     Replacefile( CurrentTaskPointer );
  757.     SetUpTheTaskbar;
  758.     exit;
  759.   end;
  760.   if ActiveButton = BitBtn6 then
  761.   begin
  762.     If CurrentTaskPointer + 1 > TotalTaskEntries then exit;
  763.     Replacefile( CurrentTaskPointer + 1 );
  764.     SetUpTheTaskbar;
  765.     exit;
  766.   end;
  767.   if ActiveButton = BitBtn7 then
  768.   begin
  769.     if CurrentTaskPointer + 2 > TotalTaskEntries then exit;
  770.     Replacefile( CurrentTaskPointer + 2 );
  771.     SetUpTheTaskbar;
  772.     exit;
  773.   end;
  774. end;
  775.  
  776. procedure TCCTaskBarForm.Delete1Click(Sender: TObject);
  777. begin
  778.   if ActiveButton = BitBtn5 then
  779.   begin
  780.     if TotalTaskEntries = 0 then exit;
  781.     DeleteTasksFrom( CurrentTaskPointer );
  782.     AddFile1.Enabled := true;
  783.     SetUpTheTaskbar;
  784.     exit;
  785.   end;
  786.   if ActiveButton = BitBtn6 then
  787.   begin
  788.     If CurrentTaskPointer + 1 > TotalTaskEntries then exit;
  789.     DeleteTasksFrom( CurrentTaskPointer + 1 );
  790.     AddFile1.Enabled := true;
  791.     SetUpTheTaskbar;
  792.     exit;
  793.   end;
  794.   if ActiveButton = BitBtn7 then
  795.   begin
  796.     if CurrentTaskPointer + 2 > TotalTaskEntries then exit;
  797.     DeleteTasksFrom( CurrentTaskPointer + 2 );
  798.     AddFile1.enabled := true;
  799.     SetUpTheTaskbar;
  800.     exit;
  801.   end;
  802. end;
  803.  
  804. procedure TCCTaskBarForm.MoveUp1Click(Sender: TObject);
  805. var HoldingRecord : TBRecord;
  806. begin
  807.   if ActiveButton = BitBtn5 then
  808.   begin
  809.     if TotalTaskEntries = 0 then exit;
  810.     if CurrentTaskPointer = 1 then exit;
  811.     HoldingRecord := ThePTBArray[ CurrentTaskPointer - 1 ]^;
  812.     ThePTBArray[ CurrentTaskPointer - 1 ]^ :=
  813.      ThePTBArray[ CurrentTaskPointer ]^;
  814.     ThePTBArray[ CurrentTaskPointer ]^ := HoldingRecord;
  815.     SetUpTheTaskbar;
  816.     exit;
  817.   end;
  818.   if ActiveButton = BitBtn6 then
  819.   begin
  820.     If CurrentTaskPointer + 1 > TotalTaskEntries then exit;
  821.     HoldingRecord := ThePTBArray[ CurrentTaskPointer ]^;
  822.     ThePTBArray[ CurrentTaskPointer  ]^ :=
  823.      ThePTBArray[ CurrentTaskPointer + 1 ]^;
  824.     ThePTBArray[ CurrentTaskPointer + 1 ]^ := HoldingRecord;
  825.     SetUpTheTaskbar;
  826.     exit;
  827.   end;
  828.   if ActiveButton = BitBtn7 then
  829.   begin
  830.     if CurrentTaskPointer + 2 > TotalTaskEntries then exit;
  831.     HoldingRecord := ThePTBArray[ CurrentTaskPointer + 1 ]^;
  832.     ThePTBArray[ CurrentTaskPointer +  1 ]^ :=
  833.      ThePTBArray[ CurrentTaskPointer + 2 ]^;
  834.     ThePTBArray[ CurrentTaskPointer + 2 ]^ := HoldingRecord;
  835.     SetUpTheTaskbar;
  836.     exit;
  837.   end;
  838. end;
  839.  
  840. procedure TCCTaskBarForm.MoveDown1Click(Sender: TObject);
  841. var HoldingRecord : TBRecord;
  842. begin
  843.   if ActiveButton = BitBtn5 then
  844.   begin
  845.     if TotalTaskEntries = 0 then exit;
  846.     if CurrentTaskPointer = TotalTaskEntries then exit;
  847.     HoldingRecord := ThePTBArray[ CurrentTaskPointer + 1 ]^;
  848.     ThePTBArray[ CurrentTaskPointer + 1 ]^ :=
  849.      ThePTBArray[ CurrentTaskPointer ]^;
  850.     ThePTBArray[ CurrentTaskPointer  ]^ := HoldingRecord;
  851.     SetUpTheTaskbar;
  852.     exit;
  853.   end;
  854.   if ActiveButton = BitBtn6 then
  855.   begin
  856.     If CurrentTaskPointer + 1 >= TotalTaskEntries then exit;
  857.     HoldingRecord := ThePTBArray[ CurrentTaskPointer + 2 ]^;
  858.     ThePTBArray[ CurrentTaskPointer + 2 ]^ :=
  859.      ThePTBArray[ CurrentTaskPointer + 1 ]^;
  860.     ThePTBArray[ CurrentTaskPointer + 1 ]^ := HoldingRecord;
  861.     SetUpTheTaskbar;
  862.     exit;
  863.   end;
  864.   if ActiveButton = BitBtn7 then
  865.   begin
  866.     if CurrentTaskPointer + 2 >= TotalTaskEntries then exit;
  867.     HoldingRecord := ThePTBArray[ CurrentTaskPointer + 3 ]^;
  868.     ThePTBArray[ CurrentTaskPointer +  3 ]^ :=
  869.      ThePTBArray[ CurrentTaskPointer + 2 ]^;
  870.     ThePTBArray[ CurrentTaskPointer + 2 ]^ := HoldingRecord;
  871.     SetUpTheTaskbar;
  872.     exit;
  873.   end;
  874. end;
  875.  
  876. procedure TCCTaskBarForm.BitBtn5MouseDown(Sender: TObject;
  877.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  878. begin
  879.   ActiveButton := BitBtn5;
  880. end;
  881.  
  882. procedure TCCTaskBarForm.BitBtn6MouseDown(Sender: TObject;
  883.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  884. begin
  885.   ActiveButton := BitBtn6;
  886. end;
  887.  
  888. procedure TCCTaskBarForm.BitBtn7MouseDown(Sender: TObject;
  889.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  890. begin
  891.   ActiveButton := BitBtn7;
  892. end;
  893.  
  894. procedure TCCTaskBarForm.BitBtn5MouseUp(Sender: TObject;
  895.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  896. begin
  897.   if Button = mbRight then PopupMenu2.PopUp( CCTaskBarForm.Left +
  898.    BitBtn5.Left + 40 , CCTaskBarForm.Top + BitBtn5.Top - 40 );
  899. end;
  900.  
  901. procedure TCCTaskBarForm.BitBtn6MouseUp(Sender: TObject;
  902.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  903. begin
  904.   if Button = mbRight then PopupMenu2.PopUp( CCTaskBarForm.Left +
  905.    BitBtn6.Left + 40 , CCTaskBarForm.Top + BitBtn6.Top - 40 );
  906. end;
  907.  
  908. procedure TCCTaskBarForm.BitBtn7MouseUp(Sender: TObject;
  909.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  910. begin
  911.   if Button = mbRight then PopupMenu2.PopUp( CCTaskBarForm.Left +
  912.    BitBtn7.Left + 40 , CCTaskBarForm.Top + BitBtn7.Top - 40 );
  913. end;
  914.  
  915. end.
  916.